﻿using Unity.Interception.PolicyInjection.Pipeline;
using Unity.Interception.PolicyInjection.Policies;

namespace NoteHelper.Test
{
    /// <summary>
    /// 事务处理标记
    /// a.注意需要继承HandlerAttribute;
    /// b.重写了基类的CreateHandler方法 返回事务拦截器TransactionInterceptor
    /// </summary>
    public class TransactionAttribute : HandlerAttribute
    {
        public override ICallHandler CreateHandler(Unity.IUnityContainer container)
        {
            return new TransactionInterceptor(Level, Order);
        }
        /// <summary>
        /// 事务隔离级别
        /// </summary>
        public int Level { get; private set; }

        /// <summary>
        /// 自定义事务隔离级别
        /// </summary>
        /// <param name="level"></param>
        public TransactionAttribute(int level)
        {
            this.Level = level;
        }
        /// <summary>
        /// 使用数据库默认隔离级别
        /// </summary>
        public TransactionAttribute() : this(0) { }
    }
}
